/**
 * Created by jovi on 3/11/16.
 */
$(document).ready(function () {

    window.share = {
        imgUrl : 'http://wechat.xiqing.info/wechat/share/share.jpg',
        link : 'http://point.xiqing.info/test1/share/share.html',
        title : '扫码认证长安福特车主，赚积分，赢好礼，享特权！',
        desc : '扫码认证长安福特车主，赚积分，赢好礼，享特权！'
    }

    $.getJSON('http://wechat.xiqing.info/wechat/getInfo?url='+encodeURIComponent(location.href.split('#')[0]), function(response){
        WeiXinShare(response);
    });


    function WeiXinShare(response) {

        console.log(response)

        wx.config({
            debug:true,
            appId:response.appId,
            timestamp:response.timestamp,
            nonceStr: response.nonceStr,
            signature: response.signature,
            jsApiList: [
                'checkJsApi',
                'onMenuShareTimeline',
                'onMenuShareAppMessage',
                'onMenuShareQQ',
                'onMenuShareWeibo',
            ]
        });

        wx.checkJsApi({
            jsApiList: [
                'onMenuShareTimeline',
                'onMenuShareAppMessage',
                'onMenuShareQQ',
                'onMenuShareWeibo',
            ],
            success: function (res) {
                //alert(JSON.stringify(res));
            }
        });



        wx.ready(function () {
            wx.onMenuShareTimeline({
                title: window.share.title,
                link: window.share.link,
                imgUrl: window.share.imgUrl,
                desc:  window.share.desc,
                success: function (res) {
                    //alert('T'+JSON.stringify(res));
                },
                cancel: function (res) {
                    // 用户取消分享后执行的回调函数
                    //alert('cancel:'+JSON.stringify(res));
                },
                fail: function (res) {
                    //alert(JSON.stringify(res));
                }
            });

            wx.onMenuShareAppMessage({
                title: window.share.title,
                link: window.share.link,
                imgUrl: window.share.imgUrl,
                desc:  window.share.desc,
                success: function (res) {
                    //alert('s:'+JSON.stringify(res));
                },
                cancel: function (res) {
                    //alert('cancel:'+JSON.stringify(res));
                },
                fail: function (res) {
                    //alert("F:"+JSON.stringify(res));
                }
            });


            wx.onMenuShareQQ({
                title: window.share.title,
                link: window.share.link,
                imgUrl: window.share.imgUrl,
                desc:  window.share.desc,
                success: function (res) {
                    //alert('s:'+JSON.stringify(res));
                },
                cancel: function (res) {
                    //alert('cancel:'+JSON.stringify(res));
                },
                fail: function (res) {
                    //alert("F:"+JSON.stringify(res));
                }
            });


            wx.onMenuShareWeibo({
                title: window.share.title,
                link: window.share.link,
                imgUrl: window.share.imgUrl,
                desc:  window.share.desc,
                success: function (res) {
                    //alert('s:'+JSON.stringify(res));
                },
                cancel: function (res) {
                    //alert('cancel:'+JSON.stringify(res));
                },
                fail: function (res) {
                    //alert("F:"+JSON.stringify(res));
                }
            });
            wx.error(function(res){
                //alert('cancel:'+JSON.stringify(res));
            });

        });

    }
});